package com.foreknow.view;

import com.foreknow.bean.Guestbook;
import com.foreknow.service.impl.GuestbookServiceImpl;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Insert extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Insert frame = new Insert();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Insert() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblName = new JLabel("name");
		lblName.setBounds(33, 10, 54, 15);
		contentPane.add(lblName);
		
		textField = new JTextField();
		textField.setBounds(95, 7, 66, 21);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("phone");
		lblNewLabel.setBounds(33, 62, 54, 15);
		contentPane.add(lblNewLabel);
		
		textField_1 = new JTextField();
		textField_1.setBounds(95, 59, 66, 21);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		JLabel lblEmail = new JLabel("email");
		lblEmail.setBounds(33, 111, 54, 15);
		contentPane.add(lblEmail);
		
		textField_2 = new JTextField();
		textField_2.setBounds(95, 108, 66, 21);
		contentPane.add(textField_2);
		textField_2.setColumns(10);
		
		JLabel lblTitle = new JLabel("title");
		lblTitle.setBounds(218, 10, 54, 15);
		contentPane.add(lblTitle);
		
		textField_3 = new JTextField();
		textField_3.setBounds(282, 7, 66, 21);
		contentPane.add(textField_3);
		textField_3.setColumns(10);
		
		JLabel lblContent = new JLabel("content");
		lblContent.setBounds(218, 65, 54, 15);
		contentPane.add(lblContent);
		
		textField_4 = new JTextField();
		textField_4.setBounds(282, 59, 66, 21);
		contentPane.add(textField_4);
		textField_4.setColumns(10);
		
		JLabel lblCreatedtime = new JLabel("createdtime");
		lblCreatedtime.setBounds(196, 111, 76, 15);
		contentPane.add(lblCreatedtime);
		
		textField_5 = new JTextField();
		textField_5.setBounds(282, 108, 66, 21);
		contentPane.add(textField_5);
		textField_5.setColumns(10);
		
		JButton button = new JButton("\u786E\u8BA4\u6DFB\u52A0");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				GuestbookServiceImpl guestbookService = new GuestbookServiceImpl();
				Guestbook guestbook = new Guestbook();
				guestbook.setName(textField.getText());
				guestbook.setPhone(textField_1.getText());
				guestbook.setEmail(textField_2.getText());
				guestbook.setTitle(textField_3.getText());
				guestbook.setContent(textField_4.getText());
				guestbook.setCreatedtime(textField_5.getText());
				int a = guestbookService.add(guestbook);
				System.out.println(a);
				MainWindow window = new MainWindow();
				Insert.this.dispose();
				//tianjia
			}
		});
		button.setBounds(123, 184, 173, 40);
		contentPane.add(button);
		this.setVisible(true);
	}

}
